Skip to content

libcamera: prefer udmabuf over dma-heaps - #464

Draft
Wenmeng Liu (wenmliu) wants to merge 1 commit into
qualcomm-linux:mainfrom
wenmliu:main
Draft

libcamera: prefer udmabuf over dma-heaps#464
Wenmeng Liu (wenmliu) wants to merge 1 commit into
qualcomm-linux:mainfrom
wenmliu:main

Conversation

@wenmliu

Copy link
Copy Markdown

On Hamoa, CMA memory is currently insufficient for libcamera operation at some resolutions. Reorder the buffer allocator provider list so that /dev/udmabuf is tried before the CMA and system dma-heaps. Components that allow the udmabuf provider (software ISP, virtual pipeline) now use it whenever /dev/udmabuf is available, instead of falling back to it only when the dma-heaps can not be opened.

The change is carried as a qcom-specific patch applied through a libcamera bbappend.

On Hamoa, CMA memory is currently insufficient for libcamera operation
at some resolutions. Reorder the buffer allocator provider list so that
/dev/udmabuf is tried before the CMA and system dma-heaps. Components
that allow the udmabuf provider (software ISP, virtual pipeline) now use
it whenever /dev/udmabuf is available, instead of falling back to it
only when the dma-heaps can not be opened.

The change is carried as a qcom-specific patch applied through a
libcamera bbappend.

Signed-off-by: Wenmeng Liu <wenmeng.liu@oss.qualcomm.com>
@wenmliu

Copy link
Copy Markdown
Author

kernel config PR: qualcomm-linux/kernel-topics#1805

@github-actions

Copy link
Copy Markdown

Test run workflow

Test jobs for commit fe7e479

qcom-distro
Pass: 5 | Fail: 0 | Total: 5
qcom-distro_linux-qcom-6.18
Pass: 3 | Fail: 2 | Total: 5

@test-reporting-app

Copy link
Copy Markdown

Test Results

1 files   -  18  1 suites   - 77   2m 14s ⏱️ - 1h 33m 33s
7 tests  -  72  7 ✅  -  68  0 💤 ±0  0 ❌  - 4 
9 runs   - 509  9 ✅  - 505  0 💤 ±0  0 ❌  - 4 

Results for commit fe7e479. ± Comparison against base commit 2c0f42b.

This pull request removes 72 tests.
0_BT_FW_KMD_Service ‑ BT_FW_KMD_Service
0_hotplug ‑ hotplug
10_AudioRecord ‑ AudioRecord
10_Docker_Kernel_Config ‑ Docker_Kernel_Config
11_EFI_Variable_Validation ‑ EFI_Variable_Validation
11_Ethernet ‑ Ethernet
12_DSP_AudioPD ‑ DSP_AudioPD
12_Kubernetes_Kernel_Config ‑ Kubernetes_Kernel_Config
13_Docker_Kernel_Config ‑ Docker_Kernel_Config
13_Logging_Journalctl_Validation ‑ Logging_Journalctl_Validation
…

@lumag

Copy link
Copy Markdown
Contributor

I think this is a more generic problem, to be solved with libcamera itself. If the allocator can't provide enough memory, the libcamera should be able to fallback to the other allocators. This is especially true for the CMA allocators where we know that memory space is limited.

@jwrdegoede

Hans de Goede (jwrdegoede) commented Sep 10, 2026

Copy link
Copy Markdown

The upstream linux-media (e.g. gstreamer) direction seems to be to use udmabuf more and more where ever possible now that it is generally available in most distro configurations.

I think trying relatively unlimited udmabuf memory before CMA heaps makes sense from a not wasting scarce resources like CMA. OTOH IIRC the try CMA first approach is there for platforms where e.g. the video hw encoder which may sit after libcamera can only operate on CMA memory.

So I think that rather then carrying a downstream patch the following should be done:

  1. Make the order in which allocators are tried configurable through libcamera's configfile mechanism allowing changing of the order by dropping a /etc/libcamera/configuration.yaml file. This alone should be sufficient for meta-qcom for now, by meta-qcom using this new config mechanism.
  2. Allow pipeline-handlers to provide a pipeline-handler specific default order which to use when the config file does not specify any order. pipeline-handlers is how libcamera deals with platform differences. So this will allow the camss pipeline-handler I'm working on to make trying udmabuf first the default on Qualcomm platforms.

Dmitry Baryshkov (@lumag)'s idea of falling back to another allocator is interesting but I think that will complicate things quite a bit. E.g. in case of platforms where we actually want CMA to be tried first, returning a udmabuf backed dmabuf may cause errors elsewhere (e.g. the video-encoder), so I'm not sure how helpful this will be.

I think that a configurable setting in which order to try the allocators should solve this nicely.

@lumag

Copy link
Copy Markdown
Contributor

Wenmeng Liu (@wenmliu) I think, Hans de Goede (@jwrdegoede) 's reply means: please open a merge request against libcamera, once agreed there, please backport it to QLI.

@lumag
Dmitry Baryshkov (lumag) marked this pull request as draft September 10, 2026 13:20
@jwrdegoede

Copy link
Copy Markdown

Ack, I was about to write: to be clear my suggestion to fix this should be done upstream first.

@jwrdegoede

Copy link
Copy Markdown

p.s. :

  1. For more info on the config mechanism see: https://docs.libcamera.org/master/runtime_configuration.html and also please update runtime_configuration.rst when adding a setting for this.
  2. Note upstream does not take pull-requests they use an email based patch-workflow closely mirroring the kernel's. So subscribe to the libcamera-devel list: https://lists.libcamera.org/listinfo/libcamera-devel and after writing the patches git send-email them to the libcamera-devel list.

@wenmliu

Copy link
Copy Markdown
Author

Sounds good. I'll work on the changes and submit them upstream.

@lool

Copy link
Copy Markdown

The upstream linux-media (e.g. gstreamer) direction seems to be to use udmabuf more and more where ever possible now that it is generally available in most distro configurations.

Just an FYI but you probably already know: UDMABUF is not enabled in defconfig

@jwrdegoede

Copy link
Copy Markdown

The upstream linux-media (e.g. gstreamer) direction seems to be to use udmabuf more and more where ever possible now that it is generally available in most distro configurations.

Just an FYI but you probably already know: UDMABUF is not enabled in defconfig

Interesting, I'm not really a defconfig user, but that is a good point and one which is probably worth fixing... Let me discuss this with Robert Mader who has been pushing this from the gstreamer side.

@wenmliu

Copy link
Copy Markdown
Author

The upstream linux-media (e.g. gstreamer) direction seems to be to use udmabuf more and more where ever possible now that it is generally available in most distro configurations.

Just an FYI but you probably already know: UDMABUF is not enabled in defconfig

Yes, that's why I submitted a PR to enable UDMABUF for Qualcomm platforms:
qualcomm-linux/kernel-topics#1805

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants